package LRU;

import java.util.HashMap;
import java.util.Map;

public class 无重复字符的最长子串3 {


        public int lengthOfLongestSubstring(String s) {
            char[]chars=s.toCharArray();
            Map<Character,Integer> map=new HashMap<Character,Integer>();
            if(s.length()==0)return 0;
            int l=0;
            int ans = 1;
            for(int i =0;i<chars.length;i++){
                if(map.containsKey(chars[i])){
                    int index=map.get(chars[i]);
                    while(l<=index){
                        map.remove(chars[l++]);
                    }

                }

                map.put(chars[i],i);
                ans=Math.max(ans,i-l+1);
            }
            return ans;
        }

}
